﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using IBLL;
using BllFactory;
using System.IO;
using System.Text;
using System.Web;
using ETWebApi2.Models;
using System.Web.SessionState;
using System.Net.Mail;

namespace ETWebApi2.Controllers
{
    public class DefaultController : ApiController
    {
        [HttpGet, Route("bind")]
        public void Bind()
        {
            string checkCode = CreateCode(6);
            WriteEmail mail = new WriteEmail();
            mail.Send("验证码：" + checkCode);
        }
        public string CreateCode(int codeLength)
        {
            string so = "1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
            string[] strArr = so.Split(',');
            string code = "";
            Random rand = new Random();
            for (int i = 0; i < codeLength; i++)
            {
                code += strArr[rand.Next(0, strArr.Length)];
            }
            HttpContext.Current.Session["CheckCode"] = code;
            HttpContext.Current.Session.Timeout = 20;
            return code;
        }
    }

}